package com.hengsu.bitmapqiekuai;

import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import java.util.List;

/**
 * 作者：twopai on 2017/4/12.
 * 邮箱：twopai@hotmail.com
 * 开门式跳转
 */
public class MainActivity extends AppCompatActivity {

    private LinearLayout animLayout;
    private ImageView leftLayout;
    private ImageView rightLayout;
    private FrameLayout mainRLayout;
    private Button btnDJ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        animLayout = (LinearLayout) findViewById(R.id.animLayout);
        leftLayout = (ImageView) findViewById(R.id.leftLayout);
        rightLayout = (ImageView) findViewById(R.id.rightLayout);
        mainRLayout = (FrameLayout) findViewById(R.id.mainRLayout);

        btnDJ = (Button) findViewById(R.id.btnDJ);
    }

    public void btnDJ(View view) {
        Bitmap bitmap0 = ScreenImgCut.takeScreenShot(this);//截屏
        Log.e("ScreenImgCut","height2="+bitmap0.getHeight()+",with2="+bitmap0.getWidth());
        List<ImagePiece> imagePieces = BitmapCutUtils.split(bitmap0, 1, 2);//裁剪成一行两列
        int height = imagePieces.get(0).getBitmap().getHeight();
        Log.e("ScreenImgCut","height3="+height+",with3="+imagePieces.get(0).getBitmap().getWidth());
        int height3 = imagePieces.get(1).getBitmap().getHeight();
        Log.e("ScreenImgCut","height4="+height+",with4="+imagePieces.get(1).getBitmap().getWidth());
        leftLayout.setImageBitmap(imagePieces.get(0).getBitmap());
        rightLayout.setImageBitmap(imagePieces.get(1).getBitmap());
        animLayout.setVisibility(View.VISIBLE);
        btnDJ.setVisibility(View.INVISIBLE);
//        mainRLayout.setBackgroundResource(R.drawable.whatsnew_bg);
        Animation leftOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate_left);
        Animation rightOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate_right);
        leftLayout.setAnimation(leftOutAnimation);
        rightLayout.setAnimation(rightOutAnimation);
        leftOutAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                mainRLayout.setBackgroundColor(getResources().getColor(R.color.bgColor));
            }
            @Override
            public void onAnimationRepeat(Animation animation) {
            }
            @Override
            public void onAnimationEnd(Animation animation) {
                leftLayout.setVisibility(View.GONE);
                rightLayout.setVisibility(View.GONE);
                Intent intent = new Intent(MainActivity.this,Main2Activity.class);
                MainActivity.this.startActivity(intent);
                MainActivity.this.finish();
                overridePendingTransition(R.anim.zoom_out_enter, R.anim.zoom_out_exit);
            }
        });
    }
}
